﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Web.group
{
    public partial class pbright : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(Request["phonebookid"]))
            {
                throw new Base.CustomException("缺少参数phonebookid");
            }

            Hashtable phonebook = PhoneBook.Group.PhoneBook.get(Request["phonebookid"]);
            if (phonebook == null)
            {
                throw new Base.CustomException("参数phonebookid不正确");
            }

            Hashtable user = PhoneBook.Users.Users.get(Commons.StrUtil.FormatValue(Session["userid"]));
            if (!user["groupid"].Equals(phonebook["groupid"]))
            {
                throw new Base.CustomException("无权限设置此通讯录");
            }
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            IList<string> departments = uctree_right.GetSelDepartment();

            PhoneBook.Group.PbRight.reset(Request["phonebookid"], "0", (IList)departments);

            IList<string> employees = uctree_right.GetSelEmployee();

            PhoneBook.Group.PbRight.reset(Request["phonebookid"], "1", (IList)employees);
            Helper.ShowMessage(u_message, controls.UCMessageType.success, "保存成功");

            Hashtable phonebook = PhoneBook.Group.PhoneBook.get(Request["phonebookid"]);
            AddLog("修改了通讯录({0})的查看权限", phonebook["phonebookname"]);
        }

        protected void btn_save_member_Click(object sender, EventArgs e)
        {
            IList<string> departments = uctree_member.GetSelDepartment();

            PhoneBook.Group.PbMember.reset(Request["phonebookid"], "0", (IList)departments);

            IList<string> employees = uctree_member.GetSelEmployee();

            PhoneBook.Group.PbMember.reset(Request["phonebookid"], "1", (IList)employees);

            IList<string> bos = uctree_member.GetSelBranchOffice();
            PhoneBook.Group.PbMember.reset(Request["phonebookid"], "2", (IList)bos);

            Helper.ShowMessage(u_message1, controls.UCMessageType.success, "保存成功");

            Hashtable phonebook = PhoneBook.Group.PhoneBook.get(Request["phonebookid"]);
            AddLog("修改了通讯录({0})中的成员", phonebook["phonebookname"]);
        }
    }
}